# -*- coding: utf-8 -*-
from odoo import models,api,fields
from odoo.exceptions import UserError

class WizardFixVoucherName(models.Model):
    _name = 'wizard.fix.voucher.name'
    _description = '修改凭证编号'

    voucher_id = fields.Many2one('account.voucher', string='凭证')
    name = fields.Char(string='凭证编号', compute='compute_name', readonly=False, store=True)

    @api.depends('voucher_id')
    def compute_name(self):
        for record in self:
            if record.voucher_id:
                record.name = record.voucher_id.name
            else:
                record.name = ''

    def action_change(self):
        """修改凭证编号"""
        if self.name:
            self.voucher_id.name = self.name
        else:
            raise UserError('凭证编号不能为空！')